/* reduction des choix du select en tapant dans le champ search */
function reduce_choices(val, champ1, champ2)
{
var x=document.getElementById(champ1);
var y=document.getElementById(champ2);
var patt = new RegExp(val, "i");
var option=document.createElement("option");
var txt = "";
var len=x.length;
var len2=y.length;
var i, j;
var t, s;
for (i=0;i<len;i++)
  {
  t=len-i-1;
  if ( !patt.test(x.options[t].text) )
    {
    option=document.createElement("option");
    option.text=x.options[t].text;
    option.value=x.options[t].value;
    y.add(option, null);
    x.remove(t);
    }
  }
for (j=0;j<len2;j++)
  {
  s=len2-j-1;
  if ( patt.test(y.options[s].text) )
    {
    option=document.createElement("option");
    option.text=y.options[s].text;
    option.value=y.options[s].value;
    x.add(option, null);
    y.remove(s);
    }
  }
}

/* afficher ou cacher des élements par leur class */
function show_by_class(sup)
{
x = document.getElementsByClassName(sup);

l = x.length;
for (i=0; i<l; i++)
	{
	if (x[i].style.display == 'none')
		{
		x[i].style.display='block';
		}
	else
		{
		x[i].style.display='none';
		}
	}

buttonClass = 'button' + sup;
y = document.getElementsByClassName(buttonClass);
/* document.getElementById(buttonClass).innerHTML = 'test2'; */
l = y.length;
for (i=0; i<l; i++)
	{
	y.innerHTML = 'test';
	}
}

/* cacher tous les éléments d'une class ou tout afficher si tous cachés */
function hide_by_class(sup)
{
x = document.getElementsByClassName(sup);
l = x.length;
j = 0;
for (i=0; i<l; i++)
	{
	if ( x[i].style.display!='none')
		{
		j += 1;
		}
	x[i].style.display='none';
	}
if (j == 0)
	{
	for (i=0; i<l; i++)
		{
		x[i].style.display='block';
		}
	}
}

/* changer du contenu xtml */
function SwitchContent(fieldID, link)
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    x = document.getElementById(fieldID);
    x.innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET",link ,false);
xmlhttp.send();
}


/* ajouter du contenu html */
function AddContent(fieldID, link)
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    x = document.getElementById(fieldID);
    x.innerHTML+=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET",link ,false);
xmlhttp.send();
}

/* module de mise à jour shop et prod */
function update(typeid, link)
{
if (document.getElementById(typeid).style.display == 'none')
	{
	link1 = link + 'shop/' + typeid + 'A';
	}else{
	link1 = link + 'shop/' + typeid + 'D';
	}
link2 = link + 'prod';

show_by_class(typeid);

SwitchContent('shop', link1);

SwitchContent('prod', link2);
}